<?php

$tmp = new Template('pan_files');

empty( $_GET['act'] ) && $_GET['act'] = 'list';
switch ( $_GET['act'] ) {
  case 'add':
    if ( !empty($_FILES['filename']) ) {
      $up = new upload( 'filename' );
      $up->save();
      page::redirect( '?act=list' );
      die();
    }
    $tmp = new Form();
    $tmp->file( 'New file' );
    $tmp->submit();
    break;
  case 'list':
  default:
    $sql = "SELECT u.`id` , u.`file` , u.`name` , u.`date` , `users`.`name` AS `author`
          FROM `:1` AS u
          LEFT JOIN `users` ON ( u.`author` = `users`.`id` )
          ORDER BY `name`";
    $tmp->assign( 'files', db::q($sql, upload::$table ) );
    break;
}

page::$html->assign( 'content', $tmp );

?>